#include "IntroState.h"


IntroState IntroState::m_IntroState;

sf::Vector2f buttonSize2 = sf::Vector2f(240,40);
sf::Color buttonColor2 = sf::Color::White;

void IntroState::Init(sf::RenderWindow& window){

    // +++ VIEWS +++
    view.setCenter(window.getSize().x / 2, window.getSize().y / 2);
    view.setSize(window.getSize().x, window.getSize().y);
    window.setView(view);

    // +++ BACKGROUND IMAGE +++
    bg.loadFromFile("resources/background.jpg");
    background.setTexture(bg);


    // +++ TGUI Stuff +++
    gui2.setWindow(window);
    gui2.setGlobalFont("resources/arial.ttf");

    tgui::Button::Ptr button(gui2);
    button->load("resources/Black.conf");
    button->setSize(buttonSize2.x, buttonSize2.y);
    button->setPosition(300, 100);
    button->setText("Start Game");
    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setCallbackId(1);
    button->setTextColor(buttonColor2);

    tgui::Button::Ptr button2(gui2);
    button2->load("resources/Black.conf");
    button2->setSize(buttonSize2.x, buttonSize2.y);
    button2->setPosition(300, 150);
    button2->setText("Testbed");
    button2->bindCallback(tgui::Button::LeftMouseClicked);
    button2->setCallbackId(2);
    button2->setTextColor(buttonColor2);

}

void IntroState::Cleanup(){}

void IntroState::Pause(){}
void IntroState::Resume(){}

void IntroState::Events(GameEngine* game, sf::RenderWindow& window){

    while (window.pollEvent(event)){
        // Close the window and end the game when X clicked
        if (event.type == sf::Event::Closed){
            game->Quit();
        }

        gui2.handleEvent(event);

        // The callback loop
        tgui::Callback callback;

        while (gui2.pollCallback(callback)){

            // Transition to Game State
            if (callback.id == 1){
                game->ChangeState( TestState::Instance());
            }
            // Transition to Test2 State
            if (callback.id == 2){
                game->ChangeState( Test2::Instance());
            }

        }
    }
}

void IntroState::Update(GameEngine* game, sf::RenderWindow& window){

}

void IntroState::Render(GameEngine* game, sf::RenderWindow& window){

    window.clear(sf::Color::White);

    window.draw(background);
    gui2.draw();
    window.display();


}
